"""关键词提取工具 - 使用 jieba 分词"""
import logging
import jieba.analyse
from config.settings import Config

jieba.setLogLevel(logging.INFO)


def get_keywords(content):
    """提取关键词"""
    content_length = len(content)
    if content_length <= 5:
        top_k = 2
    elif 5 < content_length <= 10:
        top_k = 4
    elif 10 < content_length <= 15:
        top_k = 6
    elif 15 < content_length <= 20:
        top_k = 8
    else:
        top_k = 10
    jieba.load_userdict(Config.DICT_FILE)
    words = jieba.analyse.extract_tags(content, topK=top_k)
    keywords = ",".join(words)
    return keywords
